#ifndef _APP_FLASH_H_
#define _APP_FLASH_H_

#include "bsp_flash.h"

//PartNo
#define FLASH_INFORMATION_ADDR              USERDATA_BASE
//属性参数存在(userdata+32)
#define FLASH_PARAMETER_ADDR                ((uint32_t)(USERDATA_BASE + 32))

#define PAGE_SIZE               0x800
#define FIRMWARE_SIZE           0x14000             //app大小
#define BOOTLOADER_SIZE     (FLASH_SIZE-FIRMWARE_SIZE)    //app相对起始地址
#define FLASH_APP0_ADDR     (FLASH_START_ADDR+BOOTLOADER_SIZE)
#define FLASH_END_ADDR      (FLASH_START_ADDR+FLASH_SIZE-1)
//升级参数存储起始地址
#define FLASH_OTA_ADDR      (FLASH_START_ADDR+BOOTLOADER_SIZE-PAGE_SIZE)

//ota升级flash规划
#define FLASH_OTA_STATE         FLASH_OTA_ADDR
#define FLASH_OTA_VERSION0    (FLASH_OTA_STATE+0x01)
#define FLASH_OTA_VERSION1    (FLASH_OTA_VERSION0+0x03)
#define FLASH_OTA_DATA_LENTH  (FLASH_OTA_VERSION1+0x03)
#define FLASH_OTA_DATA_CRC    (FLASH_OTA_DATA_LENTH+0x03)
#define FLASH_OTA_END_DATA    (FLASH_OTA_DATA_CRC+0x04)

#define OTA_END_DATA_LENGTH         (0x10)      //firmware跳转前尾部核对代码是否正确
typedef struct OTAPara{
    unsigned char ota_state;
    unsigned char ota_version0[3];
    unsigned char ota_version1[3];
    unsigned char ota_data_length[3];
    unsigned char ota_data_crc[4];
    unsigned char ota_end_data[OTA_END_DATA_LENGTH];
}OTAPara;


typedef enum ENUM_OTA_HARDWARE_VERSION{
  DEFALT_VERSION          = 0x00,
  STM32F103RCT6_VERSION       = 0x11,
  STM32F401RCT6_VERSION       = 0x12,
  EFR32FG14P231F128GM32_VERSION   = 0x21,
}ENUM_OTA_HARDWARE_VERSION;

typedef struct OTAParaFame{
    struct OTAPara para;
}OTAParaFame;

void WriteReadPartNum(void);
#endif
